package tables

import (
	"peilian-api/app/global/variable"
)

type UserUploadRecord struct { // 用户导数据记录
	Model
	User       *User
	UserID     uint   `json:"user_id" gorm:"type:uint"`
	OriginFile string `json:"origin_file" gorm:"varchar(100);default:\"\";comment:文件上传的路径"`
	ErrorFile  string `json:"error_file" gorm:"varchar(100);default:\"\";comment:文件上传失败错误信息"`
}

func (s *UserUploadRecord) TableName() string {
	return "user_upload_record"
}

// 添加记录
func AddRecord(value *UserUploadRecord) (int64, error) {
	d := variable.DB.MySQL.Save(&value)
	if d.Error != nil {
		return 0, d.Error
	}
	return d.RowsAffected, nil
}

// 更新记录
func UpdateRecordByWhere(upd map[string]interface{}, where map[string]interface{}) (int64, error) {
	d := variable.DB.MySQL.Model(UserUploadRecord{}).Where(where).Updates(upd)
	if d.Error != nil {
		return 0, d.Error
	}
	return d.RowsAffected, nil
}
